package org.lanqiao.dao;

import java.util.List;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.lanqiao.Db.DBDriverFactory;
import org.lanqiao.bean.EduTeacherBean;
import org.lanqiao.bean.EduUserBean;


public class LoginDao {
	
	public boolean isLogined(EduTeacherBean eub){
		boolean isLo=false;
		//数据库语句
		String strSql="SELECT * FROM EDUTEACHER WHERE TEACHERNAME=? AND TEACHERPASSWORD=?";
		List<EduTeacherBean> lisUser=(List<EduTeacherBean>) DBDriverFactory.getDbDriverInstance().query(strSql, new BeanListHandler<EduTeacherBean>(EduTeacherBean.class), 
				new Object[]{eub.getTeachername(),eub.getTeacherpassword()});
		// 根据查询结果判定用户是否登录成功
		if(lisUser!=null&&lisUser.size()>0){
			isLo=true;
		}
		return isLo;
	}

	public EduUserBean getStudentLoginInfo(EduUserBean eub) {
		//获取学生信息的sql语句
		String strSql="SELECT * FROM EDUUSER WHERE USERNAME=? AND USERPASSWORD=?";
		EduUserBean studentInfo=DBDriverFactory.getDbDriverInstance().query(strSql,
				new BeanHandler<>(EduUserBean.class),new Object[]{eub.getUsername(),eub.getUserpassword()});
		//把学生的信息传回c层
		return studentInfo;
	}

	public EduTeacherBean getTeacherInfo(EduTeacherBean etd) {
		//数据库语句
		String strSql="SELECT * FROM EDUTEACHER WHERE TEACHERNAME=? AND TEACHERPASSWORD=?";
		EduTeacherBean TeaInfo=DBDriverFactory.getDbDriverInstance().query(strSql, new BeanHandler<EduTeacherBean>(EduTeacherBean.class), 
				new Object[]{etd.getTeachername(),etd.getTeacherpassword()});
		// 根据查询结果返回老师的信息
		return TeaInfo;
	}

}
